//https://leetcode.cn/problems/string-to-url-lcci/

char* replaceSpaces(char* S, int length) {
    int count = 0;
    for (int i = 0; i < length; i++)
    {
        if (S[i] == ' ')
        {
            count++;
        }
    }

    int lengthS = count * 2 + length;
    S[lengthS--] = '\0';
    for (int i = length - 1; i >= 0; i--)
    {
        if (S[i] == ' ')
        {
            S[lengthS--] = '0';
            S[lengthS--] = '2';
            S[lengthS--] = '%';
            continue;
        }

        S[lengthS--] = S[i];
    }

    return S;
}
